package com.dongdongmovie.controller;

import com.dongdongmovie.pojo.Role;
import com.dongdongmovie.service.RoleResource_Service;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("RoleResource")
public class RoleResource_Controller {

    //注入service
    @DubboReference
    private RoleResource_Service resource_service;

    //跳转show
    @RequestMapping("tzshow")
    public String tzshow() {
        return "RoleResource/show";
    }

    //跳转add
    @RequestMapping("tzadd")
    public String tzadd() {
        return "RoleResource/add";
    }

    //跳转update
    @RequestMapping("tzupdate")
    public String tzupdate(Integer roleId, Model m) {
        Role r = resource_service.showbyId(roleId);
        m.addAttribute("r", r);
        return "RoleResource/update";
    }

    //查询全部
    @ResponseBody
    @RequestMapping("show")
    public List<Role> show() {
        return resource_service.show();
    }

    //添加数据
    @ResponseBody
    @RequestMapping("add")
    public int add(Role r, Integer[] roleIds) {
        return resource_service.add(r, roleIds);
    }

    //修改数据
    @ResponseBody
    @RequestMapping("update")
    public int update(Role r, Integer[] roleIds) {
        return resource_service.update(r, roleIds);
    }

    //删除数据
    @ResponseBody
    @RequestMapping("delete")
    public int delete(Integer roleId) {
        return resource_service.delete(roleId);
    }

}
